'--------------------------------------------------------------------------------------
'Copyright: (c) 2010 Bentley Systems, Incorporated.
'--------------------------------------------------------------------------------------
'
'  This file is part of structural-gc.
'
'  structural-gc is free software: you can redistribute it and/or modify
'  it under the terms of the GNU General Public License as published by
'  the Free Software Foundation, either version 2 of the License, or
'  (at your option) any later version.
'
'  structural-gc is distributed in the hope that it will be useful,
'  but WITHOUT ANY WARRANTY; without even the implied warranty of
'  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'  GNU General Public License for more details.
'
'  You should have received a copy of the GNU General Public License
'  along with structural-gc.  If not, see <http://www.gnu.org/licenses/>
'--------------------------------------------------------------------------------------

Imports Bentley.GenerativeComponents.GeneralPurpose
Imports Bentley.Interop.TFCom
Imports Bentley.Interop.STFCom
Imports System.Windows.Forms

Namespace Forms

    Public Class SectionPickerForm
        Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.
        'Do not modify it using the code editor.
        Friend WithEvents m_okButton As System.Windows.Forms.Button
        Friend WithEvents m_cancelButton As System.Windows.Forms.Button
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents m_sectionTableTextBox As System.Windows.Forms.TextBox
        Friend WithEvents m_sectionNameComboBox As System.Windows.Forms.ComboBox
        Friend WithEvents m_sectionTypeComboBox As System.Windows.Forms.ComboBox
        Friend WithEvents Label3 As System.Windows.Forms.Label
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.m_okButton = New System.Windows.Forms.Button
            Me.m_cancelButton = New System.Windows.Forms.Button
            Me.Label1 = New System.Windows.Forms.Label
            Me.Label2 = New System.Windows.Forms.Label
            Me.m_sectionTableTextBox = New System.Windows.Forms.TextBox
            Me.m_sectionNameComboBox = New System.Windows.Forms.ComboBox
            Me.m_sectionTypeComboBox = New System.Windows.Forms.ComboBox
            Me.Label3 = New System.Windows.Forms.Label
            Me.SuspendLayout()
            '
            'm_okButton
            '
            Me.m_okButton.BackColor = System.Drawing.SystemColors.Control
            Me.m_okButton.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.m_okButton.Location = New System.Drawing.Point(104, 160)
            Me.m_okButton.Name = "m_okButton"
            Me.m_okButton.Size = New System.Drawing.Size(80, 38)
            Me.m_okButton.TabIndex = 2
            Me.m_okButton.Text = "OK"
            '
            'm_cancelButton
            '
            Me.m_cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.m_cancelButton.Location = New System.Drawing.Point(206, 161)
            Me.m_cancelButton.Name = "m_cancelButton"
            Me.m_cancelButton.Size = New System.Drawing.Size(80, 38)
            Me.m_cancelButton.TabIndex = 3
            Me.m_cancelButton.Text = "Cancel"
            '
            'Label1
            '
            Me.Label1.Location = New System.Drawing.Point(16, 20)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(195, 27)
            Me.Label1.TabIndex = 2
            Me.Label1.Text = "Section table:"
            '
            'Label2
            '
            Me.Label2.Location = New System.Drawing.Point(21, 108)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(142, 25)
            Me.Label2.TabIndex = 3
            Me.Label2.Text = "Section name:"
            '
            'm_sectionTableTextBox
            '
            Me.m_sectionTableTextBox.Location = New System.Drawing.Point(139, 16)
            Me.m_sectionTableTextBox.Name = "m_sectionTableTextBox"
            Me.m_sectionTableTextBox.Size = New System.Drawing.Size(234, 26)
            Me.m_sectionTableTextBox.TabIndex = 0
            Me.m_sectionTableTextBox.Text = ""
            '
            'm_sectionNameComboBox
            '
            Me.m_sectionNameComboBox.Location = New System.Drawing.Point(140, 106)
            Me.m_sectionNameComboBox.Name = "m_sectionNameComboBox"
            Me.m_sectionNameComboBox.Size = New System.Drawing.Size(236, 28)
            Me.m_sectionNameComboBox.TabIndex = 4
            '
            'm_sectionTypeComboBox
            '
            Me.m_sectionTypeComboBox.Location = New System.Drawing.Point(140, 67)
            Me.m_sectionTypeComboBox.Name = "m_sectionTypeComboBox"
            Me.m_sectionTypeComboBox.Size = New System.Drawing.Size(236, 28)
            Me.m_sectionTypeComboBox.TabIndex = 6
            '
            'Label3
            '
            Me.Label3.Location = New System.Drawing.Point(21, 71)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(119, 26)
            Me.Label3.TabIndex = 5
            Me.Label3.Text = "Section type:"
            '
            'SectionPickerForm
            '
            Me.AcceptButton = Me.m_okButton
            Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19)
            Me.CancelButton = Me.m_cancelButton
            Me.ClientSize = New System.Drawing.Size(387, 214)
            Me.Controls.Add(Me.m_sectionTypeComboBox)
            Me.Controls.Add(Me.Label3)
            Me.Controls.Add(Me.m_sectionNameComboBox)
            Me.Controls.Add(Me.m_sectionTableTextBox)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.m_cancelButton)
            Me.Controls.Add(Me.m_okButton)
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "SectionPickerForm"
            Me.ShowInTaskbar = False
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "Section Picker"
            Me.ResumeLayout(False)

        End Sub

#End Region

    Friend Property ExpressionText() As String
        Get
                Return """" & m_sectionTableTextBox.Text & ":" & m_sectionNameComboBox.Text & """"
        End Get
            Set(ByVal Value As String)
                Value = Value.Replace("""", "")
                Dim pos As Integer = Value.IndexOf(":")
                If pos < 0 Then pos = Value.Length

                Dim SubS1 As String = ""
                Dim SubS2 As String = ""

                TextTools.Substring(Value, 0, pos, SubS1)
                TextTools.Substring(Value, 0, pos + 1, SubS2)

                m_sectionTableTextBox.Text = SubS1
                m_sectionNameComboBox.Text = SubS2

                'Change it above, below is the old syntax
                'm_sectionTableTextBox.Text = TextTools.Substring(Value, 0, pos)
                'm_sectionNameComboBox.Text = TextTools.Substring(Value, pos + 1)
            End Set
    End Property

        Private Sub SectionPickerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '        Dim section As STFSection
            '        Dim sectionList As New STFSectionList

            m_sectionTypeComboBox.Items.Clear()
            m_sectionTypeComboBox.Items.Add("Wide Flanges")
            m_sectionTypeComboBox.Items.Add("Single Angles")
            m_sectionTypeComboBox.Items.Add("Double Angles")
            m_sectionTypeComboBox.Items.Add("Structural Tees")
            m_sectionTypeComboBox.Items.Add("Channels")
            m_sectionTypeComboBox.Items.Add("Double Channels")
            m_sectionTypeComboBox.Items.Add("Rectangular Tubes")
            m_sectionTypeComboBox.Text = "Wide Flanges"
        End Sub

        Private Sub m_sectionTypeComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_sectionTypeComboBox.SelectedIndexChanged
            Dim section As STFSection
            Dim sectionList As New STFSectionList

            Dim oldCursor As Cursor = System.Windows.Forms.Cursor.Current
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
            Try
                sectionList.InitFromTFSecMgr()
            Finally
                System.Windows.Forms.Cursor.Current = oldCursor
            End Try
            Dim cnt As Integer
            cnt = sectionList.GetCount()

            m_sectionNameComboBox.Items.Clear()
            Dim icnt As Integer
            Dim sectionName As String
            For icnt = 0 To cnt - 1
                section = sectionList.GetSectionByIndex(icnt)
                Dim sType As Integer
                section.GetType(sType)
                sectionName = section.GetName

                If (m_sectionTypeComboBox.Text = "Wide Flanges") Then
                    If sType = 1 Then
                        m_sectionNameComboBox.Items.Add(sectionName)
                    End If
                End If

                If (m_sectionTypeComboBox.Text = "Single Angles") Then
                    If sType = 2 Then
                        m_sectionNameComboBox.Items.Add(sectionName)
                    End If
                End If

                If (m_sectionTypeComboBox.Text = "Channels") Then
                    If sType = 3 Then
                        m_sectionNameComboBox.Items.Add(sectionName)
                    End If
                End If

                If (m_sectionTypeComboBox.Text = "Structural Tees") Then
                    If sType = 5 Then
                        m_sectionNameComboBox.Items.Add(sectionName)
                    End If
                End If
            Next

            m_sectionNameComboBox.SelectedIndex = 0
            m_sectionTableTextBox.Text = "us.stf"
        End Sub

        Private Sub m_okButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_okButton.Click

        End Sub
    End Class

End Namespace